class Music {
    constructor() {
        this.audio = {};
        this.lyric = [];
        this.src = '';
        this.img = 'http://img4.imgtn.bdimg.com/it/u=3413101525,1189252897&fm=26&gp=0.jpg';
        this.playState = 'list';
        this.isPlay = false;
        this.duration = 0;
        this.currentTime = 0;
        this.dom = null;
        this.initMusicPlayer();
    }
    play() {
        if (this.dom) {
            this.dom.play();
            this.isPlay = true;
        }
    }
    pause() {
        if (this.dom) {
            this.dom.pause();
            this.isPlay = false;
        }
    }
    setSrc(url) {
        this.src = url;
        this.dom.src = this.src;
        this.dom.oncanplay = ()  => {
            this.duration = this.dom.duration;
        }
    }
    changePlayState(state) {
        this.playState = state;
        this.dom.loop = this.playState === 'loop';
    }
    initMusicPlayer() {
        this.dom = document.createElement('audio');
        this.dom.src = this.src;
        this.dom.loop = this.playState === 'loop';
        document.body.appendChild(this.dom);
    }
}

export default Music;
